package comprehensive_case;

import java.util.Random;
import java.util.Scanner;

public class 双色球彩票 {
    public static void main(String[] args) {
        int[] arr = huoqushuzu(); // 随机获取的号码
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        System.out.println("==================================");
        int[] arrInpute = userInpute(); // 用户输入的号码
        int redCount = 0;
        int blueCount = 0;

        // 判断中奖个数 红球
        for (int i = 0; i < arrInpute.length - 1; i++) {
            for (int j = 0; j < arr.length - 1; j++) {
                if (arr[j] == arrInpute[i]) {
                    redCount++;
                    break;
                }
            }
        }
        // 判断蓝球中奖个数
        if (arr[arr.length - 1] == arrInpute[arrInpute.length - 1]) {
            blueCount++;
        }
        System.out.println("红球中奖个数：" + redCount);
        System.out.println("红球中奖个数：" + blueCount);
        if (redCount == 6 && blueCount == 1) {
            System.out.println("恭喜你中奖1000万");
        } else if (redCount == 6 && blueCount == 0) {
            System.out.println("恭喜你中奖500万");
        } else if (redCount == 5 && blueCount == 1) {
            System.out.println("恭喜你中奖3000");
        } else if ((redCount == 5 && blueCount == 0) || (redCount == 4 && blueCount == 1)) {
            System.out.println("恭喜你中奖200");
        } else if ((redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 1)) {
            System.out.println("恭喜你中奖10");
        } else if ((redCount == 2 && blueCount == 1) || (redCount == 1 && blueCount == 1)
                || (redCount == 0 && blueCount == 1)) {
            System.out.println("恭喜你中奖5");
        } else {
            System.out.println("谢谢参与");
        }

    }

    public static int[] userInpute() {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[7];
        for (int i = 0; i <= 5;) {
            System.out.println("请输入第" + (i + 1) + "个红球号码：");
            int InputeRedNumber = sc.nextInt();
            if (InputeRedNumber >= 1 && InputeRedNumber <= 33) {
                if (contain(arr, InputeRedNumber)) {
                    arr[i] = InputeRedNumber;
                    i++;
                } else {
                    System.out.println("输入了重复的数字");
                }
            } else {
                System.out.println("输入的数字不在范围内");
            }
        }
        System.out.println("请输入蓝球号码：");
        int InputeBlueNumber = sc.nextInt();

        while (true) {
            if (InputeBlueNumber >= 1 && InputeBlueNumber <= 16) {
                arr[arr.length - 1] = InputeBlueNumber;
                break;
            } else {
                System.out.println("输入的数字不在范围内");
            }
        }
        sc.close();
        return arr;

    }

    public static int[] huoqushuzu() {
        int[] arr = new int[7];
        Random r = new Random();
        for (int i = 0; i < 6;) {
            int rednumber = r.nextInt(33) + 1;
            if (contain(arr, rednumber)) {
                arr[i] = rednumber;
                i++;
            }
        }
        int bluenumber = r.nextInt(16) + 1;
        arr[6] = bluenumber;
        return arr;
    }

    // 判断数组中是否存在这个数字
    public static boolean contain(int[] arr, int number) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number) {
                return false;
            }
        }
        return true;
    }
}
